#!/usr/bin/python3.8.9
# -*- coding: utf-8 -*-

# @Author  : Tina Yu
# @Time    : 2021-6-14 17:05

# 嵌套


# 遍历列表
# alien_0 = {'color': 'green', 'points': 5}
# alien_1 = {'color': 'yellow', 'points': 10}
# alien_2 = {'color': 'red', 'points': 1}
# aliens = [alien_0, alien_1, alien_2]
# # 遍历列表
# for alien in aliens:
#     print(alien)

# 字典列表
def test_recycle_list():
    aliens = []
    # 创建30个绿色的外星人
    for alien_green in range(30):
        new_alien = {'color': 'green', 'points': 5, 'speed': 'slow'}
        aliens.append(new_alien)

    # 如果前三个中有颜色为绿色的，则改为黄色
    for alien in aliens[:3]:
        if alien['color'] == 'green':
            alien['color'] = 'yellow'
            alien['speed'] = 'medium'
            alien['points'] = 10
        elif alien['color'] == 'yellow':
            alien['color'] = 'red'
            alien['speed'] = 'fast'
            alien['points'] = 15

    # 显示前5个外星人
    for alien in aliens[:5]:
        print(alien)
    print(f'绿色外星人共计：{len(aliens)}')


# 在字典中存储列表
def test_list_in_dict():
    pizza = {
        'crust': 'thick',
        'topping': ['mushrooms', 'extra cheese']
    }
    print(f'You ordered a {pizza["crust"]}-crust pizza with the following toppings:')

    for topping in pizza['topping']:
        print('\t' + topping)


# 在字典中存字典
def test_dict_in_dict():
    users = {
        'person1': {
            'name': 'yuhuifei',
            'age': '18',
            'heigh': 162,
        },
        'person2': {
            'name': 'yukexin',
            'age': '11',
            'heigh': 182,
        }
    }
    for user_name, user_info in users.items():
        print(f'\n{user_name}：')
        name = user_info['name']
        age = user_info['age']
        heigh = user_info['heigh']

        print(f'\t姓名为：{name}')
        print(f'\t年龄为：{age}')
        print(f'\t身高为：{heigh}')


# 课后练习6-1
def test_practice_61():
    friends = {
        'zhouhuan': {'first_name': 'zhou', 'last_name': 'Viky', 'age': '30', 'city': 'guiyang'},
        'zhongwenhui': {'first_name': 'zhong', 'last_name': 'wenhui', 'age': '29', 'city': 'zhenjiang'},
        'yuhuifei': {'first_name': 'yu', 'last_name': 'Tina', 'age': '31', 'city': 'changchun'}
    }
    for name, info in friends.items():
        print(f'*****************************************')
        print(f'{name}的信息：')
        print(f'\tFirstName ：{info["first_name"].title()}')
        print(f'\tLastName ：{info["last_name"]}')
        print(f'\t年龄是：{info["age"]}')
        print(f'\t家乡是：{info["city"]}\n')



